package com.szyt.basicframe.handler;

import com.szyt.basicframe.annotation.UserNameUnique;
import com.szyt.basicframe.common.OperationTypeEnum;
import com.szyt.basicframe.pojo.request.usermanagement.UpdateUserRequest;
import com.szyt.basicframe.service.ISysUserService;
import com.szyt.basicframe.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.reflect.Field;

@Slf4j
public class UserNameUniqueValidator implements ConstraintValidator<UserNameUnique, String> {

    @Autowired
    private ISysUserService userService;

    private OperationTypeEnum operationType;

    @Override
    public void initialize(UserNameUnique constraintAnnotation) {
        this.operationType=constraintAnnotation.type();
    }

    @Override
    public boolean isValid(String userName, ConstraintValidatorContext context) {
        boolean exist = userService.existUserName(null, userName);
        return !exist;
    }
}
